pygame战棋游戏制作之战棋回合切换(五) 您所在的位置:网站首页 战棋游戏 制作 pygame战棋游戏制作之战棋回合切换(五)

pygame战棋游戏制作之战棋回合切换(五)

2024-06-14 15:36| 来源: 网络整理| 查看: 265

简介

前面我们已经完成了战棋地图的绘制,棋子的设置,光标的设置,接下来我们将要开始实现rpg游戏的灵魂——回合切换。

正文

回合切换主要是通过棋子列表判断,当列表为空时,触发回合切换的函数。因此我们创建一个上帝类来控制整个游戏的流程,因此我们会把主函数移到上帝类。

class God: def __init__(self,screen): self.screen = screen self.player_chess = [] self.neutral_chess = [] self.current_action = "" self.current_chess = [] self.m = Map() self.c = Cursor(0,0,self.m) def load(self, player, enemy): self.player_chess = player self.enemy_chess = enemy self.current_action = "" self.current_chess = [] def turn(self): if self.current_action == "player": # 我方回合结束 self.current_action = "enemy" self.current_chess = self.enemy_chess[:] else: # 敌人回合结束或者开局 self.current_action = "player" self.current_chess = self.player_chess[:] def main(): pygame.init() clock = pygame.time.Clock() # 设置时钟 clock.tick(10) # 每秒执行60次 d = Dogface() d.set_cur_index(3,5) self.m.load_map(d) store = Store() store.set_cur_index(4,7) self.m.load_map(store) b = Block() self.screen = pygame.display.set_mode((self.m.width,self.m.height)) # 显示窗口 color = (255,255,0) self.screen.fill(color) while True: self.m.create(self.screen,b) self.screen.blit(self.c.cursor[self.c.status],(self.c.cursorX*self.m.block,self.c.cursorY*self.m.block)) pygame.display.update() # 轮询事件 for event in pygame.event.get(): if event.type == pygame.QUIT: # 如果检测到事件是关闭窗口 sys.exit() elif (event.type == pygame.KEYDOWN and event.key == pygame.K_UP): self.c.move_up() elif (event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN): self. c.move_down() elif (event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT): self.c.move_left() elif (event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT): self.c.move_right() elif (event.type == pygame.KEYDOWN and event.key == pygame.K_a) and self.c.status: if isinstance(self.c.get_cursor_index_obj,Removable): begin = self.c.current_obj.get_cur_index() end = self.c.get_cur_index() # 移动 self.m.change_map(begin,end,self.c.current_obj) self.c.cancel() elif (event.type == pygame.KEYDOWN and event.key == pygame.K_a): self.c.catch()


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有